/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package webservice.notafiscaleletronica.capturaXML;

import br.com.javac.v200.consrecinfe.SignatureType;
import br.com.javac.v200.consrecinfe.TEnderEmi;
import br.com.javac.v200.consrecinfe.TEndereco;
import br.com.javac.v200.consrecinfe.TLocal;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Dest;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS00;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS10;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS20;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS30;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS40;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS51;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS60;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS70;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMS90;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMSPart;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMSSN101;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMSSN102;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMSSN201;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMSSN202;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMSSN500;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMSSN900;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ICMS.ICMSST;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.II;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.IPI;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.IPI.IPINT;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.IPI.IPITrib;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Emit;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Ide;
import br.com.javac.v200.consrecinfe.TNfeProc;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Avulsa;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Cana;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Cobr;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Cobr.Fat;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Compra;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.COFINS;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.COFINS.COFINSAliq;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.COFINS.COFINSNT;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.COFINS.COFINSOutr;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.COFINS.COFINSQtde;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.COFINSST;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.ISSQN;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.PIS;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.PIS.PISAliq;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.PIS.PISNT;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.PIS.PISOutr;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.PIS.PISQtde;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Imposto.PISST;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Det.Prod;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Exporta;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Total;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Total.ICMSTot;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Total.ISSQNtot;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Total.RetTrib;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Transp;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Transp.RetTransp;
import br.com.javac.v200.consrecinfe.TNFe.InfNFe.Transp.Transporta;
import br.com.javac.v200.consrecinfe.TVeiculo;
import camada.bancodedados.daoimplemente.xml.XMLDAOImpl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import camada.bancodedados.daoimplemente.consultasistema.ConsultasSimplesSistemaDAOImpl;

/**
 *
 * @author Ícaro
 */
public class lerXMLJAXBThread extends Thread {

    File arq;
    
    public lerXMLJAXBThread(File arq){
        this.arq = arq;
    }

    @Override
    public void run() {

        synchronized (this) {

            boolean result = lerXMLJAXB(arq.getPath());

            if (result == true) {

                arq.renameTo(new File("C:\\Seloma\\XML\\Entrada\\", arq.getName()));
                arq.delete();

            }
        }

        this.notify();

    }

    public boolean lerXMLJAXB(String xmlArq) {

        boolean result = false;

        try {

            TNfeProc wNfe = getNFe(lerXML(xmlArq));

            if (wNfe != null) {

                
                ConsultasSimplesSistemaDAOImpl daoConsulta = new ConsultasSimplesSistemaDAOImpl();

                int idCount = Integer.parseInt(daoConsulta.getConsultaSimplesSistema("select count(*) as result from xml_nfe where id = \"" + wNfe.getNFe().getInfNFe().getId() + "\""));

                if (idCount == 0) {

                    InfNFe infNFe = new InfNFe();

                    List<Det> listaDet = new ArrayList<Det>();
                    
                    /*
                     * Informações de Avulsa
                     */
                    if (wNfe.getNFe().getInfNFe().getAvulsa() != null) {

                        Avulsa avulsa = new Avulsa();

                        avulsa.setCNPJ(wNfe.getNFe().getInfNFe().getAvulsa().getCNPJ());
                        avulsa.setXOrgao(wNfe.getNFe().getInfNFe().getAvulsa().getXOrgao());
                        avulsa.setMatr(wNfe.getNFe().getInfNFe().getAvulsa().getMatr());
                        avulsa.setXAgente(wNfe.getNFe().getInfNFe().getAvulsa().getXAgente());
                        avulsa.setFone(wNfe.getNFe().getInfNFe().getAvulsa().getFone());
                        avulsa.setUF(wNfe.getNFe().getInfNFe().getAvulsa().getUF());
                        avulsa.setNDAR(wNfe.getNFe().getInfNFe().getAvulsa().getNDAR());
                        avulsa.setDEmi(wNfe.getNFe().getInfNFe().getAvulsa().getDEmi());
                        avulsa.setVDAR(wNfe.getNFe().getInfNFe().getAvulsa().getVDAR());
                        avulsa.setRepEmi(wNfe.getNFe().getInfNFe().getAvulsa().getRepEmi());
                        avulsa.setDPag(wNfe.getNFe().getInfNFe().getAvulsa().getDPag());

                        infNFe.setAvulsa(avulsa);

                    }

                    /*
                     * Informações de Cana
                     */
                    if (wNfe.getNFe().getInfNFe().getCana() != null) {

                        Cana cana = new Cana();

                        cana.setSafra(wNfe.getNFe().getInfNFe().getCana().getSafra());
                        cana.setRef(wNfe.getNFe().getInfNFe().getCana().getRef());
                        cana.setQTotMes(wNfe.getNFe().getInfNFe().getCana().getQTotMes());
                        cana.setQTotAnt(wNfe.getNFe().getInfNFe().getCana().getQTotAnt());
                        cana.setQTotGer(wNfe.getNFe().getInfNFe().getCana().getQTotGer());
                        cana.setVFor(wNfe.getNFe().getInfNFe().getCana().getVFor());
                        cana.setVTotDed(wNfe.getNFe().getInfNFe().getCana().getVTotDed());
                        cana.setVLiqFor(wNfe.getNFe().getInfNFe().getCana().getVLiqFor());

                        infNFe.setCana(cana);

                    }

                    
                    /*
                     * Informações de Cobrança
                     */
//                if (wNfe.getNFe().getInfNFe().getCobr().getFat() != null) {
//
//                    Cobr cobr = new Cobr();
//
//                    Fat fat = new Fat();
//
//                    fat.setNFat(wNfe.getNFe().getInfNFe().getCobr().getFat().getNFat());
//                    fat.setVOrig(wNfe.getNFe().getInfNFe().getCobr().getFat().getVOrig());
//                    fat.setVDesc(wNfe.getNFe().getInfNFe().getCobr().getFat().getVDesc());
//                    fat.setVLiq(wNfe.getNFe().getInfNFe().getCobr().getFat().getVLiq());
//
//                    cobr.setFat(fat);
//
//                    //for (Dup dup : wNfe.getNFe().getInfNFe().getCobr().getDup()) {
//                    //}
//                    infNFe.setCobr(cobr);
//
//                }

                    /*
                     * Informações de Compra
                     */
                    if (wNfe.getNFe().getInfNFe().getCompra() != null) {

                        Compra compra = new Compra();

                        compra.setXNEmp(wNfe.getNFe().getInfNFe().getCompra().getXNEmp());
                        compra.setXPed(wNfe.getNFe().getInfNFe().getCompra().getXPed());
                        compra.setXCont(wNfe.getNFe().getInfNFe().getCompra().getXCont());

                        infNFe.setCompra(compra);

                    }

                    /*
                     * Informações de Ide
                     */
                    if (wNfe.getNFe().getInfNFe().getIde() != null) {

                        Ide ide = new Ide();

                        ide.setCUF(wNfe.getNFe().getInfNFe().getIde().getCUF());
                        ide.setCNF(wNfe.getNFe().getInfNFe().getIde().getCNF());
                        ide.setNatOp(wNfe.getNFe().getInfNFe().getIde().getNatOp());
                        ide.setIndPag(wNfe.getNFe().getInfNFe().getIde().getIndPag());
                        ide.setMod(wNfe.getNFe().getInfNFe().getIde().getMod());
                        ide.setSerie(wNfe.getNFe().getInfNFe().getIde().getSerie());
                        ide.setNNF(wNfe.getNFe().getInfNFe().getIde().getNNF());
                        ide.setDEmi(wNfe.getNFe().getInfNFe().getIde().getDEmi());
                        ide.setDSaiEnt(wNfe.getNFe().getInfNFe().getIde().getDSaiEnt());
                        ide.setHSaiEnt(wNfe.getNFe().getInfNFe().getIde().getHSaiEnt());
                        ide.setTpNF(wNfe.getNFe().getInfNFe().getIde().getTpNF());
                        ide.setCMunFG(wNfe.getNFe().getInfNFe().getIde().getCMunFG());
                        ide.setTpImp(wNfe.getNFe().getInfNFe().getIde().getTpImp());
                        ide.setTpEmis(wNfe.getNFe().getInfNFe().getIde().getTpEmis());
                        ide.setCDV(wNfe.getNFe().getInfNFe().getIde().getCDV());
                        ide.setTpAmb(wNfe.getNFe().getInfNFe().getIde().getTpAmb());
                        ide.setFinNFe(wNfe.getNFe().getInfNFe().getIde().getFinNFe());
                        ide.setProcEmi(wNfe.getNFe().getInfNFe().getIde().getProcEmi());
                        ide.setVerProc(wNfe.getNFe().getInfNFe().getIde().getVerProc());
                        ide.setDhCont(wNfe.getNFe().getInfNFe().getIde().getDhCont());
                        ide.setXJust(wNfe.getNFe().getInfNFe().getIde().getXJust());

                        infNFe.setIde(ide);

                    }

                    /*
                     * Informações do emitente
                     */
                    if (wNfe.getNFe().getInfNFe().getEmit() != null) {

                        Emit emit = new Emit();

                        emit.setCNPJ(wNfe.getNFe().getInfNFe().getEmit().getCNPJ());
                        emit.setXNome(wNfe.getNFe().getInfNFe().getEmit().getXNome());
                        emit.setXFant(wNfe.getNFe().getInfNFe().getEmit().getXFant());
                        emit.setIE(wNfe.getNFe().getInfNFe().getEmit().getIE());
                        emit.setIEST(wNfe.getNFe().getInfNFe().getEmit().getIEST());
                        emit.setIM(wNfe.getNFe().getInfNFe().getEmit().getIM());
                        emit.setCNAE(wNfe.getNFe().getInfNFe().getEmit().getCNAE());
                        emit.setCRT(wNfe.getNFe().getInfNFe().getEmit().getCRT());

                        /*
                         * Informações endereço do emitente
                         */
                        if (wNfe.getNFe().getInfNFe().getEmit().getEnderEmit() != null) {

                            TEnderEmi enderEmit = new TEnderEmi();

                            enderEmit.setXLgr(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getXLgr());
                            enderEmit.setNro(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getNro());
                            enderEmit.setXCpl(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getXCpl());
                            enderEmit.setXBairro(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getXBairro());
                            enderEmit.setCMun(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getCMun());
                            enderEmit.setXMun(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getXMun());
                            enderEmit.setUF(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getUF());
                            enderEmit.setCEP(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getCEP());
                            enderEmit.setCPais(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getCPais());
                            enderEmit.setXPais(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getXPais());
                            enderEmit.setFone(wNfe.getNFe().getInfNFe().getEmit().getEnderEmit().getFone());

                            emit.setEnderEmit(enderEmit);

                        }

                        infNFe.setEmit(emit);

                    }

                    /*
                     * Informações do destinatario do XML.
                     */
                    if (wNfe.getNFe().getInfNFe().getDest() != null) {

                        Dest dest = new Dest();

                        dest.setCNPJ(wNfe.getNFe().getInfNFe().getDest().getCNPJ());
                        dest.setCPF(wNfe.getNFe().getInfNFe().getDest().getCPF());
                        dest.setXNome(wNfe.getNFe().getInfNFe().getDest().getXNome());
                        dest.setIE(wNfe.getNFe().getInfNFe().getDest().getIE());
                        dest.setISUF(wNfe.getNFe().getInfNFe().getDest().getISUF());
                        dest.setEmail(wNfe.getNFe().getInfNFe().getDest().getEmail());

                        /*
                         * Informações endereço do destinatario do XML.
                         */
                        if (wNfe.getNFe().getInfNFe().getDest().getEnderDest() != null) {

                            TEndereco enderDest = new TEndereco();

                            enderDest.setXLgr(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getXLgr());
                            enderDest.setNro(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getNro());
                            enderDest.setXCpl(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getXCpl());
                            enderDest.setXBairro(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getXBairro());
                            enderDest.setCMun(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getCMun());
                            enderDest.setXMun(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getXMun());
                            enderDest.setUF(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getUF());
                            enderDest.setCEP(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getCEP());
                            enderDest.setCPais(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getCPais());
                            enderDest.setXPais(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getXPais());
                            enderDest.setFone(wNfe.getNFe().getInfNFe().getDest().getEnderDest().getFone());

                            dest.setEnderDest(enderDest);

                        }

                        infNFe.setDest(dest);

                    }

                    /*
                     * Informações produtos
                     */
                    if (wNfe.getNFe().getInfNFe().getDet().size() > 0) {

                        Imposto imposto = new Imposto();

                        for (Det d : wNfe.getNFe().getInfNFe().getDet()) {

                            /*
                             * Informações produtos
                             */
                            Det det = new Det();

                            det.setInfAdProd(d.getInfAdProd());

                            if (d.getProd() != null) {

                                Prod prod = new Prod();

                                prod.setCProd(d.getProd().getCProd());
                                prod.setCEAN(d.getProd().getCEAN());
                                prod.setXProd(d.getProd().getXProd());
                                prod.setNCM(d.getProd().getNCM());
                                prod.setEXTIPI(d.getProd().getEXTIPI());
                                prod.setCFOP(d.getProd().getCFOP());
                                prod.setUCom(d.getProd().getUCom());
                                prod.setQCom(d.getProd().getQCom());
                                prod.setVUnCom(d.getProd().getVUnCom());
                                prod.setVProd(d.getProd().getVProd());
                                prod.setCEANTrib(d.getProd().getCEANTrib());
                                prod.setUTrib(d.getProd().getUTrib());
                                prod.setQTrib(d.getProd().getQTrib());
                                prod.setVUnTrib(d.getProd().getVUnTrib());
                                prod.setVFrete(d.getProd().getVFrete());
                                prod.setVSeg(d.getProd().getVSeg());
                                prod.setVDesc(d.getProd().getVDesc());
                                prod.setVOutro(d.getProd().getVOutro());
                                prod.setIndTot(d.getProd().getIndTot());
                                prod.setXPed(d.getProd().getXPed());
                                prod.setNItemPed(d.getProd().getNItemPed());

                                det.setProd(prod);

                            }

                            /*
                             * Informações imposto ICMS
                             */
                            ICMS icms = new ICMS();
                            
                            if (d.getImposto().getICMS().getICMS00() != null) {

                                ICMS00 icms00 = new ICMS00();

                                icms00.setOrig(d.getImposto().getICMS().getICMS00().getOrig());
                                icms00.setCST(d.getImposto().getICMS().getICMS00().getCST());
                                icms00.setModBC(d.getImposto().getICMS().getICMS00().getModBC());
                                icms00.setVBC(d.getImposto().getICMS().getICMS00().getVBC());
                                icms00.setPICMS(d.getImposto().getICMS().getICMS00().getPICMS());
                                icms00.setVICMS(d.getImposto().getICMS().getICMS00().getVICMS());

                                icms.setICMS00(icms00);

                            }

                            if (d.getImposto().getICMS().getICMS10() != null) {

                                ICMS10 icms10 = new ICMS10();

                                icms10.setOrig(d.getImposto().getICMS().getICMS10().getOrig());
                                icms10.setCST(d.getImposto().getICMS().getICMS10().getCST());
                                icms10.setModBC(d.getImposto().getICMS().getICMS10().getModBC());
                                icms10.setVBC(d.getImposto().getICMS().getICMS10().getVBC());
                                icms10.setPICMS(d.getImposto().getICMS().getICMS10().getPICMS());
                                icms10.setVICMS(d.getImposto().getICMS().getICMS10().getVICMS());

                                icms.setICMS10(icms10);

                            }

                            if (d.getImposto().getICMS().getICMS20() != null) {

                                ICMS20 icms20 = new ICMS20();

                                icms20.setOrig(d.getImposto().getICMS().getICMS20().getOrig());
                                icms20.setCST(d.getImposto().getICMS().getICMS20().getCST());
                                icms20.setModBC(d.getImposto().getICMS().getICMS20().getModBC());
                                icms20.setVBC(d.getImposto().getICMS().getICMS20().getVBC());
                                icms20.setPICMS(d.getImposto().getICMS().getICMS20().getPICMS());
                                icms20.setVICMS(d.getImposto().getICMS().getICMS20().getVICMS());

                                icms.setICMS20(icms20);

                            }

                            if (d.getImposto().getICMS().getICMS30() != null) {

                                ICMS30 icms30 = new ICMS30();

                                icms30.setOrig(d.getImposto().getICMS().getICMS30().getOrig());
                                icms30.setCST(d.getImposto().getICMS().getICMS30().getCST());
                                icms30.setModBCST(d.getImposto().getICMS().getICMS30().getModBCST());
                                icms30.setVBCST(d.getImposto().getICMS().getICMS30().getVBCST());
                                icms30.setPICMSST(d.getImposto().getICMS().getICMS30().getPICMSST());
                                icms30.setVICMSST(d.getImposto().getICMS().getICMS30().getVICMSST());

                                icms.setICMS30(icms30);

                            }

                            if (d.getImposto().getICMS().getICMS40() != null) {

                                ICMS40 icms40 = new ICMS40();

                                icms40.setOrig(d.getImposto().getICMS().getICMS40().getOrig());
                                icms40.setCST(d.getImposto().getICMS().getICMS40().getCST());
                                icms40.setVICMS(d.getImposto().getICMS().getICMS40().getVICMS());
                                icms40.setMotDesICMS(d.getImposto().getICMS().getICMS40().getMotDesICMS());

                                icms.setICMS40(icms40);

                            }

                            if (d.getImposto().getICMS().getICMS51() != null) {

                                ICMS51 icms51 = new ICMS51();

                                icms51.setOrig(d.getImposto().getICMS().getICMS51().getOrig());
                                icms51.setCST(d.getImposto().getICMS().getICMS51().getCST());
                                icms51.setModBC(d.getImposto().getICMS().getICMS51().getModBC());
                                icms51.setPRedBC(d.getImposto().getICMS().getICMS51().getPRedBC());
                                icms51.setVBC(d.getImposto().getICMS().getICMS51().getVBC());
                                icms51.setPICMS(d.getImposto().getICMS().getICMS51().getPICMS());
                                icms51.setVICMS(d.getImposto().getICMS().getICMS51().getVICMS());

                                icms.setICMS51(icms51);

                            }

                            if (d.getImposto().getICMS().getICMS60() != null) {

                                ICMS60 icms60 = new ICMS60();

                                icms60.setOrig(d.getImposto().getICMS().getICMS60().getOrig());
                                icms60.setCST(d.getImposto().getICMS().getICMS60().getCST());
                                icms60.setVBCSTRet(d.getImposto().getICMS().getICMS60().getVBCSTRet());
                                icms60.setVICMSSTRet(d.getImposto().getICMS().getICMS60().getVICMSSTRet());

                                icms.setICMS60(icms60);

                            }

                            if (d.getImposto().getICMS().getICMS70() != null) {

                                ICMS70 icms70 = new ICMS70();

                                icms70.setOrig(d.getImposto().getICMS().getICMS70().getOrig());
                                icms70.setCST(d.getImposto().getICMS().getICMS70().getCST());
                                icms70.setModBC(d.getImposto().getICMS().getICMS70().getModBC());
                                icms70.setPRedBC(d.getImposto().getICMS().getICMS70().getPRedBC());
                                icms70.setVBC(d.getImposto().getICMS().getICMS70().getVBC());
                                icms70.setPICMS(d.getImposto().getICMS().getICMS70().getPICMS());
                                icms70.setVICMS(d.getImposto().getICMS().getICMS70().getVICMS());
                                icms70.setModBCST(d.getImposto().getICMS().getICMS70().getModBCST());
                                icms70.setPMVAST(d.getImposto().getICMS().getICMS70().getPMVAST());
                                icms70.setPRedBCST(d.getImposto().getICMS().getICMS70().getPRedBCST());
                                icms70.setVBCST(d.getImposto().getICMS().getICMS70().getVBCST());
                                icms70.setPICMSST(d.getImposto().getICMS().getICMS70().getPICMSST());
                                icms70.setVICMSST(d.getImposto().getICMS().getICMS70().getVICMSST());

                                icms.setICMS70(icms70);

                            }

                            if (d.getImposto().getICMS().getICMS90() != null) {

                                ICMS90 icms90 = new ICMS90();

                                icms90.setOrig(d.getImposto().getICMS().getICMS90().getOrig());
                                icms90.setCST(d.getImposto().getICMS().getICMS90().getCST());
                                icms90.setModBC(d.getImposto().getICMS().getICMS90().getModBC());
                                icms90.setVBC(d.getImposto().getICMS().getICMS90().getVBC());
                                icms90.setPRedBC(d.getImposto().getICMS().getICMS90().getPRedBC());
                                icms90.setPICMS(d.getImposto().getICMS().getICMS90().getPICMS());
                                icms90.setVICMS(d.getImposto().getICMS().getICMS90().getVICMS());
                                icms90.setModBCST(d.getImposto().getICMS().getICMS90().getModBCST());
                                icms90.setPMVAST(d.getImposto().getICMS().getICMS90().getPMVAST());
                                icms90.setPRedBCST(d.getImposto().getICMS().getICMS90().getPRedBCST());
                                icms90.setVBCST(d.getImposto().getICMS().getICMS90().getVBCST());
                                icms90.setPICMSST(d.getImposto().getICMS().getICMS90().getPICMSST());
                                icms90.setVICMSST(d.getImposto().getICMS().getICMS90().getVICMSST());

                                icms.setICMS90(icms90);

                            }

                            if (d.getImposto().getICMS().getICMSPart() != null) {

                                ICMSPart icmsPart = new ICMSPart();

                                icmsPart.setOrig(d.getImposto().getICMS().getICMSPart().getOrig());
                                icmsPart.setCST(d.getImposto().getICMS().getICMSPart().getCST());
                                icmsPart.setModBC(d.getImposto().getICMS().getICMSPart().getModBC());
                                icmsPart.setVBC(d.getImposto().getICMS().getICMSPart().getVBC());
                                icmsPart.setPRedBC(d.getImposto().getICMS().getICMSPart().getPRedBC());
                                icmsPart.setPICMS(d.getImposto().getICMS().getICMSPart().getPICMS());
                                icmsPart.setVICMS(d.getImposto().getICMS().getICMSPart().getVICMS());
                                icmsPart.setModBCST(d.getImposto().getICMS().getICMSPart().getModBCST());
                                icmsPart.setPMVAST(d.getImposto().getICMS().getICMSPart().getPMVAST());
                                icmsPart.setPRedBCST(d.getImposto().getICMS().getICMSPart().getPRedBCST());
                                icmsPart.setVBCST(d.getImposto().getICMS().getICMSPart().getVBCST());
                                icmsPart.setPICMSST(d.getImposto().getICMS().getICMSPart().getPICMSST());
                                icmsPart.setVICMSST(d.getImposto().getICMS().getICMSPart().getVICMSST());
                                icmsPart.setPBCOp(d.getImposto().getICMS().getICMSPart().getPBCOp());
                                icmsPart.setUFST(d.getImposto().getICMS().getICMSPart().getUFST());

                                icms.setICMSPart(icmsPart);

                            }

                            if (d.getImposto().getICMS().getICMSST() != null) {

                                ICMSST icmsSt = new ICMSST();

                                icmsSt.setOrig(d.getImposto().getICMS().getICMSST().getOrig());
                                icmsSt.setCST(d.getImposto().getICMS().getICMSST().getCST());
                                icmsSt.setVBCSTRet(d.getImposto().getICMS().getICMSST().getVBCSTDest());
                                icmsSt.setVICMSSTRet(d.getImposto().getICMS().getICMSST().getVICMSSTRet());
                                icmsSt.setVBCSTDest(d.getImposto().getICMS().getICMSST().getVBCSTDest());
                                icmsSt.setVICMSSTDest(d.getImposto().getICMS().getICMSST().getVICMSSTDest());

                                icms.setICMSST(icmsSt);

                            }

                            if (d.getImposto().getICMS().getICMSSN101() != null) {

                                ICMSSN101 icmsSN101 = new ICMSSN101();

                                icmsSN101.setOrig(d.getImposto().getICMS().getICMSSN101().getOrig());
                                icmsSN101.setCSOSN(d.getImposto().getICMS().getICMSSN101().getCSOSN());
                                icmsSN101.setPCredSN(d.getImposto().getICMS().getICMSSN101().getPCredSN());
                                icmsSN101.setVCredICMSSN(d.getImposto().getICMS().getICMSSN101().getVCredICMSSN());

                                icms.setICMSSN101(icmsSN101);

                            }

                            if (d.getImposto().getICMS().getICMSSN102() != null) {

                                ICMSSN102 icmsSN102 = new ICMSSN102();

                                icmsSN102.setOrig(d.getImposto().getICMS().getICMSSN102().getOrig());
                                icmsSN102.setCSOSN(d.getImposto().getICMS().getICMSSN102().getCSOSN());

                                icms.setICMSSN102(icmsSN102);

                            }

                            if (d.getImposto().getICMS().getICMSSN201() != null) {

                                ICMSSN201 icmsSN201 = new ICMSSN201();

                                icmsSN201.setOrig(d.getImposto().getICMS().getICMSSN201().getOrig());
                                icmsSN201.setCSOSN(d.getImposto().getICMS().getICMSSN201().getCSOSN());
                                icmsSN201.setModBCST(d.getImposto().getICMS().getICMSSN201().getModBCST());
                                icmsSN201.setPMVAST(d.getImposto().getICMS().getICMSSN201().getPMVAST());
                                icmsSN201.setPRedBCST(d.getImposto().getICMS().getICMSSN201().getPRedBCST());
                                icmsSN201.setVBCST(d.getImposto().getICMS().getICMSSN201().getVBCST());
                                icmsSN201.setPICMSST(d.getImposto().getICMS().getICMSSN201().getPICMSST());
                                icmsSN201.setVICMSST(d.getImposto().getICMS().getICMSSN201().getVICMSST());
                                icmsSN201.setPCredSN(d.getImposto().getICMS().getICMSSN201().getPCredSN());
                                icmsSN201.setVCredICMSSN(d.getImposto().getICMS().getICMSSN201().getVCredICMSSN());

                                icms.setICMSSN201(icmsSN201);

                            }

                            if (d.getImposto().getICMS().getICMSSN202() != null) {

                                ICMSSN202 icmsSN202 = new ICMSSN202();

                                icmsSN202.setOrig(d.getImposto().getICMS().getICMSSN202().getOrig());
                                icmsSN202.setCSOSN(d.getImposto().getICMS().getICMSSN202().getCSOSN());
                                icmsSN202.setModBCST(d.getImposto().getICMS().getICMSSN202().getModBCST());
                                icmsSN202.setPMVAST(d.getImposto().getICMS().getICMSSN202().getPMVAST());
                                icmsSN202.setPRedBCST(d.getImposto().getICMS().getICMSSN202().getPRedBCST());
                                icmsSN202.setVBCST(d.getImposto().getICMS().getICMSSN202().getVBCST());
                                icmsSN202.setPICMSST(d.getImposto().getICMS().getICMSSN202().getPICMSST());
                                icmsSN202.setVICMSST(d.getImposto().getICMS().getICMSSN202().getVICMSST());

                                icms.setICMSSN202(icmsSN202);

                            }

                            if (d.getImposto().getICMS().getICMSSN500() != null) {

                                ICMSSN500 icmsSN500 = new ICMSSN500();

                                icmsSN500.setOrig(d.getImposto().getICMS().getICMSSN500().getOrig());
                                icmsSN500.setCSOSN(d.getImposto().getICMS().getICMSSN500().getCSOSN());
                                icmsSN500.setVBCSTRet(d.getImposto().getICMS().getICMSSN500().getVBCSTRet());
                                icmsSN500.setVICMSSTRet(d.getImposto().getICMS().getICMSSN500().getVICMSSTRet());

                                icms.setICMSSN500(icmsSN500);

                            }

                            if (d.getImposto().getICMS().getICMSSN900() != null) {

                                ICMSSN900 icmsSN900 = new ICMSSN900();

                                icmsSN900.setOrig(d.getImposto().getICMS().getICMSSN900().getOrig());
                                icmsSN900.setCSOSN(d.getImposto().getICMS().getICMSSN900().getCSOSN());
                                icmsSN900.setModBC(d.getImposto().getICMS().getICMSSN900().getModBC());
                                icmsSN900.setVBC(d.getImposto().getICMS().getICMSSN900().getVBC());
                                icmsSN900.setPRedBC(d.getImposto().getICMS().getICMSSN900().getPRedBC());
                                icmsSN900.setPICMS(d.getImposto().getICMS().getICMSSN900().getPICMS());
                                icmsSN900.setVICMS(d.getImposto().getICMS().getICMSSN900().getVICMS());
                                icmsSN900.setModBCST(d.getImposto().getICMS().getICMSSN900().getModBCST());
                                icmsSN900.setPMVAST(d.getImposto().getICMS().getICMSSN900().getPMVAST());
                                icmsSN900.setPRedBCST(d.getImposto().getICMS().getICMSSN900().getPRedBCST());
                                icmsSN900.setVBCST(d.getImposto().getICMS().getICMSSN900().getVBCST());
                                icmsSN900.setPICMSST(d.getImposto().getICMS().getICMSSN900().getPICMSST());
                                icmsSN900.setVICMSST(d.getImposto().getICMS().getICMSSN900().getVICMSST());
                                icmsSN900.setPCredSN(d.getImposto().getICMS().getICMSSN900().getPCredSN());
                                icmsSN900.setVCredICMSSN(d.getImposto().getICMS().getICMSSN900().getVCredICMSSN());

                                icms.setICMSSN900(icmsSN900);

                            }

                            imposto.setICMS(icms);

                            /*
                             * Informações imposto IPI
                             */
                            if (d.getImposto().getIPI() != null) {

                                IPI ipi = new IPI();

                                ipi.setClEnq(d.getImposto().getIPI().getClEnq());
                                ipi.setCNPJProd(d.getImposto().getIPI().getCNPJProd());
                                ipi.setCSelo(d.getImposto().getIPI().getCSelo());
                                ipi.setQSelo(d.getImposto().getIPI().getQSelo());
                                ipi.setCEnq(d.getImposto().getIPI().getCEnq());

                                if (d.getImposto().getIPI().getIPITrib() != null) {

                                    IPITrib ipiTrib = new IPITrib();

                                    ipiTrib.setCST(d.getImposto().getIPI().getIPITrib().getCST());
                                    ipiTrib.setVBC(d.getImposto().getIPI().getIPITrib().getVBC());
                                    ipiTrib.setPIPI(d.getImposto().getIPI().getIPITrib().getPIPI());
                                    ipiTrib.setQUnid(d.getImposto().getIPI().getIPITrib().getQUnid());
                                    ipiTrib.setVUnid(d.getImposto().getIPI().getIPITrib().getVUnid());
                                    ipiTrib.setVIPI(d.getImposto().getIPI().getIPITrib().getVIPI());

                                    ipi.setIPITrib(ipiTrib);

                                }

                                if (d.getImposto().getIPI().getIPINT() != null) {

                                    IPINT ipiNT = new IPINT();

                                    ipiNT.setCST(d.getImposto().getIPI().getIPINT().getCST());

                                    ipi.setIPINT(ipiNT);

                                }

                                imposto.setIPI(ipi);

                            }

                            /*
                             * Informações imposto II
                             */
                            if (d.getImposto().getII() != null) {

                                II ii = new II();

                                ii.setVBC(d.getImposto().getII().getVBC());
                                ii.setVDespAdu(d.getImposto().getII().getVDespAdu());
                                ii.setVII(d.getImposto().getII().getVII());
                                ii.setVIOF(d.getImposto().getII().getVIOF());

                                imposto.setII(ii);

                            }

                            if (d.getImposto().getISSQN() != null) {

                                ISSQN issqn = new ISSQN();

                                issqn.setVBC(d.getImposto().getISSQN().getVBC());
                                issqn.setVAliq(d.getImposto().getISSQN().getVAliq());
                                issqn.setVISSQN(d.getImposto().getISSQN().getVISSQN());
                                issqn.setCMunFG(d.getImposto().getISSQN().getCMunFG());
                                issqn.setCListServ(d.getImposto().getISSQN().getCListServ());
                                issqn.setCSitTrib(d.getImposto().getISSQN().getCSitTrib());

                                imposto.setISSQN(issqn);

                            }

                            /*
                             * Informações imposto PIS
                             */
                            if (d.getImposto().getPIS() != null) {

                                PIS pis = new PIS();

                                if (d.getImposto().getPIS().getPISAliq() != null) {

                                    PISAliq pisAliq = new PISAliq();

                                    pisAliq.setCST(d.getImposto().getPIS().getPISAliq().getCST());
                                    pisAliq.setVBC(d.getImposto().getPIS().getPISAliq().getVBC());
                                    pisAliq.setPPIS(d.getImposto().getPIS().getPISAliq().getPPIS());
                                    pisAliq.setVPIS(d.getImposto().getPIS().getPISAliq().getVPIS());

                                    pis.setPISAliq(pisAliq);

                                }

                                if (d.getImposto().getPIS().getPISQtde() != null) {

                                    PISQtde pisQtde = new PISQtde();

                                    pisQtde.setCST(d.getImposto().getPIS().getPISQtde().getCST());
                                    pisQtde.setQBCProd(d.getImposto().getPIS().getPISQtde().getQBCProd());
                                    pisQtde.setVAliqProd(d.getImposto().getPIS().getPISQtde().getVAliqProd());
                                    pisQtde.setVPIS(d.getImposto().getPIS().getPISQtde().getVPIS());

                                    pis.setPISQtde(pisQtde);

                                }

                                if (d.getImposto().getPIS().getPISNT() != null) {

                                    PISNT pisNT = new PISNT();

                                    pisNT.setCST(d.getImposto().getPIS().getPISNT().getCST());

                                    pis.setPISNT(pisNT);

                                }

                                if (d.getImposto().getPIS().getPISOutr() != null) {

                                    PISOutr pisOutr = new PISOutr();

                                    pisOutr.setCST(d.getImposto().getPIS().getPISOutr().getCST());
                                    pisOutr.setVBC(d.getImposto().getPIS().getPISOutr().getVBC());
                                    pisOutr.setPPIS(d.getImposto().getPIS().getPISOutr().getPPIS());
                                    pisOutr.setQBCProd(d.getImposto().getPIS().getPISOutr().getQBCProd());
                                    pisOutr.setVAliqProd(d.getImposto().getPIS().getPISOutr().getVAliqProd());
                                    pisOutr.setVPIS(d.getImposto().getPIS().getPISOutr().getVPIS());

                                    pis.setPISOutr(pisOutr);

                                }

                                imposto.setPIS(pis);

                            }

                            if (d.getImposto().getPISST() != null) {

                                PISST pisST = new PISST();

                                pisST.setVBC(d.getImposto().getPISST().getVBC());
                                pisST.setPPIS(d.getImposto().getPISST().getPPIS());
                                pisST.setQBCProd(d.getImposto().getPISST().getQBCProd());
                                pisST.setVAliqProd(d.getImposto().getPISST().getVAliqProd());
                                pisST.setVPIS(d.getImposto().getPISST().getVPIS());

                                imposto.setPISST(pisST);

                            }

                            /*
                             * Informações imposto COFINS
                             */
                            if (d.getImposto().getCOFINS() != null) {

                                COFINS cofins = new COFINS();

                                if (d.getImposto().getCOFINS().getCOFINSAliq() != null) {

                                    COFINSAliq cofinsAliq = new COFINSAliq();

                                    cofinsAliq.setCST(d.getImposto().getCOFINS().getCOFINSAliq().getCST());
                                    cofinsAliq.setVBC(d.getImposto().getCOFINS().getCOFINSAliq().getVBC());
                                    cofinsAliq.setPCOFINS(d.getImposto().getCOFINS().getCOFINSAliq().getPCOFINS());
                                    cofinsAliq.setVCOFINS(d.getImposto().getCOFINS().getCOFINSAliq().getVCOFINS());

                                    cofins.setCOFINSAliq(cofinsAliq);

                                }

                                if (d.getImposto().getCOFINS().getCOFINSQtde() != null) {

                                    COFINSQtde cofinsQtde = new COFINSQtde();

                                    cofinsQtde.setCST(d.getImposto().getCOFINS().getCOFINSQtde().getCST());
                                    cofinsQtde.setQBCProd(d.getImposto().getCOFINS().getCOFINSQtde().getQBCProd());
                                    cofinsQtde.setVAliqProd(d.getImposto().getCOFINS().getCOFINSQtde().getVAliqProd());
                                    cofinsQtde.setVCOFINS(d.getImposto().getCOFINS().getCOFINSQtde().getVCOFINS());

                                    cofins.setCOFINSQtde(cofinsQtde);

                                }

                                if (d.getImposto().getCOFINS().getCOFINSNT() != null) {

                                    COFINSNT cofinsNT = new COFINSNT();

                                    cofinsNT.setCST(d.getImposto().getCOFINS().getCOFINSNT().getCST());

                                    cofins.setCOFINSNT(cofinsNT);

                                }

                                if (d.getImposto().getCOFINS().getCOFINSOutr() != null) {

                                    COFINSOutr cofinsOutr = new COFINSOutr();

                                    cofinsOutr.setCST(d.getImposto().getCOFINS().getCOFINSOutr().getCST());
                                    cofinsOutr.setVBC(d.getImposto().getCOFINS().getCOFINSOutr().getVBC());
                                    cofinsOutr.setPCOFINS(d.getImposto().getCOFINS().getCOFINSOutr().getPCOFINS());
                                    cofinsOutr.setQBCProd(d.getImposto().getCOFINS().getCOFINSOutr().getQBCProd());
                                    cofinsOutr.setVAliqProd(d.getImposto().getCOFINS().getCOFINSOutr().getVAliqProd());
                                    cofinsOutr.setVCOFINS(d.getImposto().getCOFINS().getCOFINSOutr().getVCOFINS());

                                    cofins.setCOFINSOutr(cofinsOutr);

                                }

                                imposto.setCOFINS(cofins);

                            }

                            if (d.getImposto().getCOFINSST() != null) {

                                COFINSST cofinsST = new COFINSST();

                                cofinsST.setVBC(d.getImposto().getCOFINSST().getVBC());
                                cofinsST.setPCOFINS(d.getImposto().getCOFINSST().getPCOFINS());
                                cofinsST.setQBCProd(d.getImposto().getCOFINSST().getQBCProd());
                                cofinsST.setVAliqProd(d.getImposto().getCOFINSST().getVAliqProd());
                                cofinsST.setVCOFINS(d.getImposto().getCOFINSST().getVCOFINS());

                                imposto.setCOFINSST(cofinsST);
                            }

                            det.setInfAdProd(d.getInfAdProd());
                            det.setNItem(d.getNItem());

                            det.setImposto(imposto);

                            listaDet.add(det);

                        }
                    }

                    /*
                     * Importação total
                     */
                    if (wNfe.getNFe().getInfNFe().getTotal() != null) {

                        Total total = new Total();

                        if (wNfe.getNFe().getInfNFe().getTotal().getICMSTot() != null) {

                            ICMSTot icmsTot = new ICMSTot();

                            icmsTot.setVBC(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVBC());
                            icmsTot.setVICMS(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVICMS());
                            icmsTot.setVBCST(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVBCST());
                            icmsTot.setVST(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVST());
                            icmsTot.setVProd(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVProd());
                            icmsTot.setVFrete(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVFrete());
                            icmsTot.setVSeg(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVSeg());
                            icmsTot.setVDesc(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVDesc());
                            icmsTot.setVII(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVII());
                            icmsTot.setVIPI(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVIPI());
                            icmsTot.setVPIS(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVPIS());
                            icmsTot.setVCOFINS(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVCOFINS());
                            icmsTot.setVOutro(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVOutro());
                            icmsTot.setVNF(wNfe.getNFe().getInfNFe().getTotal().getICMSTot().getVNF());

                            total.setICMSTot(icmsTot);

                        }

                        if (wNfe.getNFe().getInfNFe().getTotal().getISSQNtot() != null) {

                            ISSQNtot issqnTot = new ISSQNtot();

                            issqnTot.setVServ(wNfe.getNFe().getInfNFe().getTotal().getISSQNtot().getVServ());
                            issqnTot.setVBC(wNfe.getNFe().getInfNFe().getTotal().getISSQNtot().getVBC());
                            issqnTot.setVISS(wNfe.getNFe().getInfNFe().getTotal().getISSQNtot().getVISS());
                            issqnTot.setVPIS(wNfe.getNFe().getInfNFe().getTotal().getISSQNtot().getVPIS());
                            issqnTot.setVCOFINS(wNfe.getNFe().getInfNFe().getTotal().getISSQNtot().getVCOFINS());

                            total.setISSQNtot(issqnTot);

                        }

                        if (wNfe.getNFe().getInfNFe().getTotal().getRetTrib() != null) {

                            RetTrib retTrib = new RetTrib();

                            retTrib.setVRetPIS(wNfe.getNFe().getInfNFe().getTotal().getRetTrib().getVRetPIS());
                            retTrib.setVRetCOFINS(wNfe.getNFe().getInfNFe().getTotal().getRetTrib().getVRetCOFINS());
                            retTrib.setVRetCSLL(wNfe.getNFe().getInfNFe().getTotal().getRetTrib().getVRetCSLL());
                            retTrib.setVBCIRRF(wNfe.getNFe().getInfNFe().getTotal().getRetTrib().getVBCIRRF());
                            retTrib.setVIRRF(wNfe.getNFe().getInfNFe().getTotal().getRetTrib().getVIRRF());
                            retTrib.setVBCRetPrev(wNfe.getNFe().getInfNFe().getTotal().getRetTrib().getVBCRetPrev());
                            retTrib.setVRetPrev(wNfe.getNFe().getInfNFe().getTotal().getRetTrib().getVRetPrev());

                            total.setRetTrib(retTrib);

                        }

                        infNFe.setTotal(total);

                    }

                    if (wNfe.getNFe().getInfNFe().getExporta() != null) {

                        Exporta exporta = new Exporta();

                        exporta.setUFEmbarq(wNfe.getNFe().getInfNFe().getExporta().getUFEmbarq());
                        exporta.setXLocEmbarq(wNfe.getNFe().getInfNFe().getExporta().getXLocEmbarq());

                        infNFe.setExporta(exporta);

                    }

                    if (wNfe.getNFe().getInfNFe().getRetirada() != null) {

                        TLocal tLocalRetirada = new TLocal();

                        tLocalRetirada.setCNPJ(wNfe.getNFe().getInfNFe().getRetirada().getCNPJ());
                        tLocalRetirada.setCPF(wNfe.getNFe().getInfNFe().getRetirada().getCPF());
                        tLocalRetirada.setXLgr(wNfe.getNFe().getInfNFe().getRetirada().getXLgr());
                        tLocalRetirada.setNro(wNfe.getNFe().getInfNFe().getRetirada().getNro());
                        tLocalRetirada.setXCpl(wNfe.getNFe().getInfNFe().getRetirada().getXCpl());
                        tLocalRetirada.setXBairro(wNfe.getNFe().getInfNFe().getRetirada().getXBairro());
                        tLocalRetirada.setCMun(wNfe.getNFe().getInfNFe().getRetirada().getCMun());
                        tLocalRetirada.setXMun(wNfe.getNFe().getInfNFe().getRetirada().getXMun());
                        tLocalRetirada.setUF(wNfe.getNFe().getInfNFe().getRetirada().getUF());

                        infNFe.setRetirada(tLocalRetirada);

                    }

                    if (wNfe.getNFe().getInfNFe().getEntrega() != null) {

                        TLocal tLocalEntrega = new TLocal();

                        tLocalEntrega.setCNPJ(wNfe.getNFe().getInfNFe().getEntrega().getCNPJ());
                        tLocalEntrega.setCPF(wNfe.getNFe().getInfNFe().getEntrega().getCPF());
                        tLocalEntrega.setXLgr(wNfe.getNFe().getInfNFe().getEntrega().getXLgr());
                        tLocalEntrega.setNro(wNfe.getNFe().getInfNFe().getEntrega().getNro());
                        tLocalEntrega.setXCpl(wNfe.getNFe().getInfNFe().getEntrega().getXCpl());
                        tLocalEntrega.setXBairro(wNfe.getNFe().getInfNFe().getEntrega().getXBairro());
                        tLocalEntrega.setCMun(wNfe.getNFe().getInfNFe().getEntrega().getCMun());
                        tLocalEntrega.setXMun(wNfe.getNFe().getInfNFe().getEntrega().getXMun());
                        tLocalEntrega.setUF(wNfe.getNFe().getInfNFe().getEntrega().getUF());

                        infNFe.setEntrega(tLocalEntrega);

                    }

                    if (wNfe.getNFe().getInfNFe().getTransp() != null) {

                        Transp transp = new Transp();

                        transp.setModFrete(wNfe.getNFe().getInfNFe().getTransp().getModFrete());
                        transp.setVagao(wNfe.getNFe().getInfNFe().getTransp().getVagao());
                        transp.setBalsa(wNfe.getNFe().getInfNFe().getTransp().getBalsa());

                        if (wNfe.getNFe().getInfNFe().getTransp().getTransporta() != null) {

                            Transporta transporta = new Transporta();

                            transporta.setCNPJ(wNfe.getNFe().getInfNFe().getTransp().getTransporta().getCNPJ());
                            transporta.setCPF(wNfe.getNFe().getInfNFe().getTransp().getTransporta().getCPF());
                            transporta.setXNome(wNfe.getNFe().getInfNFe().getTransp().getTransporta().getXNome());
                            transporta.setIE(wNfe.getNFe().getInfNFe().getTransp().getTransporta().getIE());
                            transporta.setXEnder(wNfe.getNFe().getInfNFe().getTransp().getTransporta().getXEnder());
                            transporta.setXMun(wNfe.getNFe().getInfNFe().getTransp().getTransporta().getXMun());
                            transporta.setUF(wNfe.getNFe().getInfNFe().getTransp().getTransporta().getUF());

                            transp.setTransporta(transporta);
                        }

                        if (wNfe.getNFe().getInfNFe().getTransp().getRetTransp() != null) {

                            RetTransp retTransp = new RetTransp();

                            retTransp.setVServ(wNfe.getNFe().getInfNFe().getTransp().getRetTransp().getVServ());
                            retTransp.setVBCRet(wNfe.getNFe().getInfNFe().getTransp().getRetTransp().getVBCRet());
                            retTransp.setPICMSRet(wNfe.getNFe().getInfNFe().getTransp().getRetTransp().getPICMSRet());
                            retTransp.setVICMSRet(wNfe.getNFe().getInfNFe().getTransp().getRetTransp().getVICMSRet());
                            retTransp.setCFOP(wNfe.getNFe().getInfNFe().getTransp().getRetTransp().getCFOP());
                            retTransp.setCMunFG(wNfe.getNFe().getInfNFe().getTransp().getRetTransp().getCMunFG());

                            transp.setRetTransp(retTransp);

                        }

                        if (wNfe.getNFe().getInfNFe().getTransp().getVeicTransp() != null) {

                            TVeiculo veicTransp = new TVeiculo();

                            veicTransp.setPlaca(wNfe.getNFe().getInfNFe().getTransp().getVeicTransp().getPlaca());
                            veicTransp.setUF(wNfe.getNFe().getInfNFe().getTransp().getVeicTransp().getUF());
                            veicTransp.setRNTC(wNfe.getNFe().getInfNFe().getTransp().getVeicTransp().getRNTC());

                            transp.setVeicTransp(veicTransp);

                        }

                        infNFe.setTransp(transp);

                    }

                    infNFe.setId(wNfe.getNFe().getInfNFe().getId());
                    infNFe.setVersao(wNfe.getNFe().getInfNFe().getVersao());

                    XMLDAOImpl daoXML = new XMLDAOImpl();

                    daoXML.setInsertsXMLDAOImpl(infNFe, listaDet, lerXML(xmlArq), wNfe.getProtNFe().getInfProt().getChNFe());

                    result = true;

                }else 
                {
                    result = true;
                }
            }

        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    @SuppressWarnings("unchecked")
    public static TNfeProc getNFe(String xml) throws Exception {
        try {
            JAXBContext context
                    = JAXBContext.newInstance(TNfeProc.class
                    );
            Unmarshaller unmarshaller = context.createUnmarshaller();
            TNfeProc nfe = unmarshaller.unmarshal(new StreamSource(new StringReader(xml)), TNfeProc.class).getValue();

            return nfe;
        } catch (JAXBException ex) {
            throw new Exception(ex.toString());
        }
    }

    private static String lerXML(String fileXML) throws IOException {
        String linha = "";
        StringBuilder xml = new StringBuilder();

        BufferedReader in = new BufferedReader(new InputStreamReader(
                new FileInputStream(fileXML)));
        while ((linha = in.readLine()) != null) {
            xml.append(linha);
        }
        in.close();

        return xml.toString();
    }

    private static void info(String log) {
        System.out.println("INFO: " + log);
    }

    private static void error(String log) {
        System.out.println("ERROR: " + log);
    }

}
